<?php
class ManageController extends AdminController{
    public function init() {
        $this->tableName='friendlink';
        parent::init();
    }

    public function indexAction() {
        $this->list=$this->model->order('ordernum asc,id asc')->getlist();
        $this->display();
    }

    public function addAction() {
        if (IS_POST){
            $param['name']=I('name','str','');
            if (!$param['name']){
                $this->error('请输入链接名称');
            }
            $param['url']=I('url','url','');
            if (!$param['url']){
                $this->error('请输入链接地址');
            }
            $param['logo']=I('logo','str','');
            $param['description']=I('description','str','');
            $param['color']=I('color','str','');
            $param['ordernum']=I('ordernum','int',50);
            $param['status']=I('status','int',1);
            $param['isbold']=I('isbold','int',0);
            $param['create_user_id']=$_SESSION['admin']['userid'];
            $param['create_time']=NOW_TIME;
            if($this->model->add($param)){
                $this->success('添加成功',U('index'));
            }else{
                $this->error('添加失败');
            }
        }
        $this->display();
    }

    public function editAction() {
        $id=I('request.id','int',0);
        $info=$this->model->where(array('id'=>$id))->find();
        if (IS_POST){
            $param['name']=I('name','str','');
            if (!$param['name']){
                $this->error('请输入链接名称');
            }
            $param['url']=I('url','url','');
            if (!$param['url']){
                $this->error('请输入链接地址');
            }
            $param['logo']=I('logo','str','');
            $param['description']=I('description','str','');
            $param['color']=I('color','str','');
            $param['ordernum']=I('ordernum','int',50);
            $param['status']=I('status','int',50);
            $param['isbold']=I('isbold','int',50);
            $param['update_user_id']=$_SESSION['admin']['userid'];
            $param['update_time']=NOW_TIME;
            $param['id']=$id;
            if ($this->model->edit($param)){
                $this->success('修改成功',U('index'));
            }else{
                $this->error('修改失败');
            }
        }
        $this->info=$info;
        $this->display();
    }
}